#coding:utf-8
import ldap
SERVER = "ldap://LDAPServer"
BASE = "DC=cminl,DC=oa"
def login(name,password):
    con = ldap.initialize(SERVER)
    try:                     
        con.set_option(ldap.OPT_REFERRALS,0)
        con.protocol_version = 3
        result = con.simple_bind_s(name,password)
        if result and result[0]==97:
            #print('name = %s,password=%s,ldap login result =%s'%( name,password,result[0]))
            return True            
           
    #except ldap.LDAPError, e:
    except:
        return False
    finally:
        con.unbind()
    return False